<template>
  <div>
      <h2>登录</h2>
      <table class="table table-bordered">
        <tbody>
          <tr>
            <td>账号</td>
            <td><input type="text" v-model="state.Name"></td>
          </tr>
          <tr>
            <td>密码</td>
            <td><input type="password" v-model="state.Pwd"></td>
          </tr>
          <tr>
            <td></td>
            <td><input type="button" value="登录" @click="log"></td>
          </tr>
        </tbody>
      </table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs,onMounted } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
import {useStore}from '../stores/user'

const route=useRoute();
const router=useRouter();

const a=useStore();

let data:any=reactive({
  state:{
    Name:'',
    Pwd:''
  }
})
let {state}=toRefs(data);

const log=()=>{

  let obj={
    Name:state.value.Name,
    Pwd:state.value.Pwd
  }
  axios({
    url:'/api/one/log',
    method:'get',
    params:obj
  }).then((res)=>{
    console.log(res)
    if(res.data.data==-1){
        alert('账号错误');
        return;
    }
    else if(res.data.data==-2){
      alert('密码错误');
      return;
    }
    else{
      a.useInfo=res.data.data;
      alert('成功')
      router.push('/Add')
      return;
    }
   
    
  }).catch((err)=>{
    console.log(err)
  })


}
</script>

<style scoped>

</style>